# -*- coding:utf-8 -*-

import json
import pickle

datas = json.load(open('data_label.json','r',encoding='utf8'))
#
# print(len(datas))

type2dicts = {"NA":0}

for dd in datas:
    for d in dd['content']:
        infos = d['info']
        ents = infos['ents']
        triples = infos['triples']

        # for ent in ents:
        #     if ent['type'] not in type2dicts:
        #         type2dicts[ent['type']] = len(type2dicts)

        for triples in triples:
            if triples['prop'] not in type2dicts:
                type2dicts[triples['prop']] = len(type2dicts)

# print(sorted(type2dicts, key=lambda x:x[0]))
# print(type2dicts)
# pickle.dump(type2dicts,open('tri_prop.pkl','wb'))

# alllen = len(datas)
# print(alllen)
# train_len = int(alllen * (9/10))
#
# train_data = datas[:train_len]
# test_data = datas[train_len:]
#
# json.dump(train_data, open('train_data.json','w',encoding='utf8'))
# json.dump(test_data, open('test_data.json','w',encoding='utf8'))
#
train_data = json.load(open('train_data.json','r',encoding='utf8'))
for d in train_data:
    print(d)

# dic = json.load(open('../prop2id.json','r',encoding='utf8'))
# dic = dict(zip(dic.values(), dic.keys()))
# pickle.dump(dic, open('../id2ent.pkl','wb'))
# print(dic)